package com.seashop.controller;

import com.seashop.response.ResponseBase;
import com.seashop.constant.BaseConstant;
import com.seashop.service.IAdminService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * @author moredln
 * @desc 管理后台登陆中心
 * @date 2020-08-04 09:39
 */
@RestController
@RequestMapping("/admin")
@Api(tags = "管理后台-登陆")
public class LoginController {

    @Autowired
    private IAdminService adminService;

    @PostMapping("/login")
    @ApiOperation(value = "登录接口", notes = "登录")
    public ResponseBase login(String username, String password) {
        if (StringUtils.isEmpty(username) || StringUtils.isEmpty(password)) {
            return ResponseBase.fail(BaseConstant.FIELD_NOT_EMPTY + "username、password");
        }
        Map<String, Object> resultMap = adminService.checkUserNameAndPassword(username, password);

        return ResponseBase.success(resultMap);
    }
}
